﻿using OA.Models;
using OA.Models.Enums;
using OA.Models.ViewModels;
using System;
using System.Data.Entity;

namespace OA.Core
{
    public class ApplicationFormCore
    {
        public static bool Save(OAContext Context, dynamic Entity)
        {
            Entity.ModificationDate = DateTime.Now;

            // 新增
            if (string.IsNullOrWhiteSpace(Entity.Id))
            {
                var Id = DateTime.Now.ToString("yyyyMMddHHmmss_fffff");
                Entity.Id = Id;
                Entity.Status = ApplicationFormState.未提交;
                Context.Entry(Entity).State = EntityState.Added;
            }
            // 编辑
            else
            {
                Context.Entry(Entity).State = EntityState.Modified;
            }
            
            return true;
        }
    }
}
